package com.avcdata.national.utils;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;

public class MyGrideView extends GridView {

    //    public MyGrideView(Context context) {
//        super(context);
//    }
//
//    public MyGrideView(Context context, AttributeSet attrs) {
//        super(context, attrs);
//    }
//
//    @Override
//    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
//        super.onMeasure(widthMeasureSpec, expandSpec);
//    }
    public boolean hasScrollBar = true;

    public MyGrideView(Context context) {
        this ( context, null );
    }

    public MyGrideView(Context context, AttributeSet attrs) {
        super ( context, attrs, 0 );
    }

    public MyGrideView(Context context, AttributeSet attrs, int defStyle) {
        super ( context, attrs, defStyle );
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int expandSpec = heightMeasureSpec;
        if (hasScrollBar) {
            expandSpec = MeasureSpec.makeMeasureSpec ( Integer.MAX_VALUE >> 2,
                    MeasureSpec.AT_MOST );
            super.onMeasure ( widthMeasureSpec, expandSpec );// 注意这里,这里的意思是直接测量出GridView的高度
        } else {
            super.onMeasure ( widthMeasureSpec, heightMeasureSpec );
        }
    }
}
